package com.neo.users.UserInfoA.service.impl;

import com.neo.users.UserInfoA.pojo.UserInfoA;
import com.neo.users.UserInfoA.mapper.UserInfoAMapper;
import com.neo.users.UserInfoA.service.UserInfoAService;
import com.neo.users.UserInfoA.pojo.Result;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
 * 用户A类型表，用于测试mp代码生成 服务实现类
 *
 * @author chenb
 * @date 2024-08-29
 */
@Service
public class UserInfoAServiceImpl implements UserInfoAService {

  @Autowired
  private UserInfoAMapper userInfoAMapper;

  @Override
  @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  public String addUserInfoA(UserInfoA userInfoA) {
    try {
      Integer count = userInfoAMapper.insertUserInfoA(userInfoA);
      if (count != null && count > 0) {
        return new Result<>(true, "新增成功").toString();
      } else {
        return new Result<>(false, "新增失败").toString();
      }
    } catch (Exception e) {
      e.printStackTrace();
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      return new Result<>(false, "新增异常").toString();
    }
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  public String deleteUserInfoA(Integer id) {
    try {
      Integer count = userInfoAMapper.deleteUserInfoA(id);
      if (count != null && count > 0) {
        return new Result<>(true, "删除成功").toString();
      } else {
        return new Result<>(false, "删除失败").toString();
      }
    } catch (Exception e) {
      e.printStackTrace();
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      return new Result<>(false, "删除异常").toString();
    }
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
  public String updateUserInfoA(UserInfoA userInfoA) {
    try {
      Integer count = userInfoAMapper.updateUserInfoA(userInfoA);
      if (count != null && count > 0) {
        return new Result<>(true, "修改成功").toString();
      } else {
        return new Result<>(false, "修改失败").toString();
      }
    } catch (Exception e) {
      e.printStackTrace();
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
      return new Result<>(false, "修改异常").toString();
    }
  }

  @Override
  public String getUserInfoAList(Integer categoryId, String goodsName, Integer shelfLifeQuantity,
      String shelfLifeUnit, String ext1, String ext2, String ext3, String isDel, Integer limit,
      Integer offset) {
    try {
      List<UserInfoA> userInfoAList = userInfoAMapper.getUserInfoAList(categoryId, goodsName,
          shelfLifeQuantity, shelfLifeUnit, ext1, ext2, ext3, isDel, limit, offset);
      if (userInfoAList != null && userInfoAList.size() > 0) {
        return new Result<>(true, userInfoAList.toString()).toString();
      } else {
        return new Result<>(true, "查询数据为空").toString();
      }
    } catch (Exception e) {
      e.printStackTrace();
      return new Result<>(false, "查询异常").toString();
    }
  }

  @Override
  public String getUserInfoACount(Integer categoryId, String goodsName, Integer shelfLifeQuantity,
      String shelfLifeUnit, String ext1, String ext2, String ext3, String isDel) {
    try {
      Integer count = userInfoAMapper.getUserInfoACount(categoryId, goodsName, shelfLifeQuantity,
          shelfLifeUnit, ext1, ext2, ext3, isDel);
      if (count != null && count > 0) {
        return new Result<>(true, count).toString();
      } else {
        return new Result<>(true, "查询数据为空").toString();
      }
    } catch (Exception e) {
      e.printStackTrace();
      return new Result<>(false, "查询异常").toString();
    }
  }
}


